<template name="mine">
  <view class="mine" style="background-color: #d53030">
    <view class="m_user">
      <view class="user_infrom">
        <image src="../../static/index/mine/user_image.png" mode=""></image>
        <text class="u_name">User{{ name }}</text>
        <text class="u_Account">{{ number }}</text>
        <view @click="openpop" class="u_Settings">
          <image src="../../static/index/mine/user_Settings.png" mode=""></image>
        </view>
      </view>
    </view>
    <view class="m_list">
      <image src="../../static/log.png" mode=""></image>
      <view class="head-list">
        <view class="head-text"> wallet </view>
        <view class="head-text1"> ₹{{ all }} </view>
      </view>
      <view class="m_lists">
        <ul class="u_list">
          <li @click="go(1)">
            <view class="u_litxt">
              <image src="../../static/index/mine/user_list1.png" mode=""></image>Personal Information
            </view>
            <image src="../../static/index/mine/user_rjian.png" class="li_right"></image>
          </li>
          <li @click="go(2)">
            <view class="u_litxt">
              <image src="../../static/index/mine/user_list1.png" mode=""></image>Customer Service
            </view>
            <image src="../../static/index/mine/user_rjian.png" class="li_right"></image>
          </li>
          <li @click="go(3)">
            <view class="u_litxt">
              <image src="../../static/index/mine/user_list2.png" mode=""></image>Feedbacks
            </view>
            <image src="../../static/index/mine/user_rjian.png" class="li_right"></image>
          </li>
          <li @click="go(4)">
            <view class="u_litxt">
              <image src="../../static/index/mine/user_list3.png" mode=""></image>Loan Agreement
            </view>
            <image src="../../static/index/mine/user_rjian.png" class="li_right"></image>
          </li>
          <li @click="go(5)" v-if="isAccountSecurity">
            <view class="u_litxt">
              <image src="../../static/index/mine/user_list3.png" mode=""></image>Account Security
            </view>
            <image src="../../static/index/mine/user_rjian.png" class="li_right"></image>
          </li>
        </ul>
		<!-- @click="banbens" -->
        <view class=""  style="font-size: 28rpx; color: #1d2129; margin-left: 64rpx">
          Version：1.0.0
        </view>
      </view>
    </view>

    <!-- <home :cur="PageCur" v-if="PageCur=='mine'" :key="commponent1Key"></home> -->
    <!-- <people v-if="PageCur=='people'" :key="commponent2Key"></people>` -->
    <view class="cu-bar tabbar bg-white shadow foot" style="height: 182rpx">
      <view :class="PageCur == 'home' ? 'action text-red' : 'action text-gray'" @click="NavChange" data-cur="home">
        <view class="cuIcon-homefill"></view>Home
      </view>
      <view :class="PageCur == 'mine' ? 'action text-red' : 'action text-gray'" @click="NavChange" data-cur="mine">
        <view class="cuIcon-peoplelist"></view>Me
      </view>
    </view>
    <uni-popup class="popupRef" ref="popup" type="center" :mask-click="false">
      <view class="popup">
        <view class="popupTitle"> Tips </view>
        <view class="popupMain" style="margin-top: 25rpx">
          <view class="popupText"> Are you sure you want to log out? </view>
        </view>
        <view class="popupBtn">
          <view @click="closepop" class="btntext">Cancel</view>
          <view @click="quit" class="btntext pay">Confirm</view>
        </view>
      </view>
    </uni-popup>
	<uni-popup ref="popup10" type="center" :mask-click="false">
		<view class="returns">
			<view class="pop-text">
				A new Customer Service Manager has been assigned to you！
			</view>
			<view class="pop-btn1">
				<button @click="sures" class="quit">Confirm</button>
				<button @click="closepopuser" class="closes">Close</button>
			</view>
		</view>
	</uni-popup>
    <!-- <uni-popup ref="popup" type="center" class="popupRef">
			<view class="popup">
				<view class="popupTitle">Tips</view>
				<view class="popupMain">
					<view class="popupText">• 22-50 years old</view>
					<view class="popupText">• Have a stable income and the ability to repay debts</view>
				</view>
				<view class="popupBtn" @click="popupClose">GOT&nbsp;&nbsp;&nbsp;IT</view>
			</view>
		</uni-popup> -->
  </view>
</template>

<script>
import { getDecryptString , getRawKey, getEncryptString } from '../../defaut';

export default {
  data() {
    return {
      PageCur: "mine",
      commponent1Key: 0,
      commponent2Key: 0,
      name: "",
      number: "",
      isAccountSecurity: false,
	  all:0,
	  nativePlug:null, //打点
    };
  },
  onLoad: function () {
	  this.usermessage()
    this.PageCur = "mine";
    ++this.commponent1Key;
    ++this.commponent2Key;
  },
  onShow() {
    (this.name = uni
      .getStorageSync("phone")
      .substring(
        uni.getStorageSync("phone").length - 4,
        uni.getStorageSync("phone").length
      )),
      (this.number = uni.getStorageSync("phone"));
  },
  mounted() {
    this.getSystemInfo()
  },
  methods: {
    //获取系统配置信息
    getSystemInfo: async function () {
      const res = await this.$http.get("/sysconfig/list1");
      if (res.data.status == 200) {
        this.isAccountSecurity = JSON.parse(getDecryptString(res.data.data, this.$password())).find(el => el.sysKey == "账号注销开关").sysVal == '开'
      }
    },
    NavChange: function (e) {
      this.PageCur = e.currentTarget.dataset.cur;
      const pages = getCurrentPages();
      const currentPage = pages[pages.length - 1];
      const routes = {
        "pages/mine/mine": 'mine',
        "pages/index/index": 'home',
      }
      if (routes[currentPage.route] == this.PageCur) return

      if (e.currentTarget.dataset.cur == "mine") {
        this.$Router.replaceAll({
          name: "mine",
        });
      } else if (e.currentTarget.dataset.cur == "home")
			uni.setStorageSync("jiance",true);
        this.$Router.replaceAll({
          name: "index",
        });
    },
    // 确认退出
    quit() {
      // #ifdef H5
     uni.removeStorageSync("token");
      uni.removeStorageSync("currentPage");
       uni.removeStorageSync("backupcopyfirst");
     		 // uni.removeStorageSync("numbersa");
     		  uni.removeStorageSync("times");
     uni.reLaunch({
       url: "/pages/login/login",
     });
	  
      uni.removeStorageSync("token");
      this.$Router.replace({ name: 'login' })
      // #endif

      // #ifdef APP-PLUS
      uni.removeStorageSync("token");
	   uni.removeStorageSync("currentPage");
	    uni.removeStorageSync("backupcopyfirst");
		 // uni.removeStorageSync("numbersa");
		  uni.removeStorageSync("times");
		   uni.removeStorageSync("huxing");
		    uni.removeStorageSync("dadian2"); uni.removeStorageSync("dadian3");
			 uni.removeStorageSync("dadian4"); uni.removeStorageSync("dadian5");
			  uni.removeStorageSync("dadian6"); 
			   uni.removeStorageSync("dadian8");
			   uni.removeStorageSync("sanfang");
	  uni.reLaunch({
	    url: "/pages/login/login",
	  });
      // if (plus.os.name.toLowerCase() === "android") {
      //   plus.runtime.quit();
      // } else {
      //   const threadClass = plus.ios.importClass("NSThread"); // 导入了iOS的 NSThread 类。
      //   const mainThread = plus.ios.invoke(threadClass, "mainThread"); // 通过调用 NSThread 类的 mainThread 方法获取主线程对象。
      //   plus.ios.invoke(mainThread, "exit"); //调用主线程对象的 exit 方法，退出应用程序。
      //   ios11
      //   plus.ios
      //     .import("UIApplication")
      //     .sharedApplication()
      //     .performSelector("exit"); //导入 UIApplication 类，调用 sharedApplication 方法获取应用程序对象，然后使用 performSelector 方法调用应用程序对象的 exit 方法,  针对iOS 11及以上版本的退出方式
      // }
      //   #endif
    },
    // 关闭退出弹窗
    closepop() {
      this.$refs.popup.close();
    },
    // 打开退出弹窗
    openpop() {
      this.$refs.popup.open("center");
    },
    // 跳转页面
    go(val) {
      if (val == 1) {
        uni.navigateTo({
          url: "/pages/authentication/authenticationdata",
        });
      } else if (val == 2) {
        // 跳转 watsapp的   联系客服
		let tel = uni.getStorageSync("kefutel");
		let name = uni.getStorageSync("kename");
		this.kefu(tel, name)
		
      } else if (val == 3) {
        uni.navigateTo({
          url: "/pages/feedback/feedback",
        });
      } else if (val == 4) {
        // uni.navigateTo({
        // 	url: "/pages/login/login"
        // })
        uni.navigateTo({
          url: "/pages/contract/contract",
        });
      } else if (val == 5) {
        uni.navigateTo({
          url: "/pages/accountsecurity/accountsecurity",
        });
      }
    },
	// 调用客服列表
	kefu(tel, name) {
		this.kefutel=tel
		this.$http.get("/baseService/list", {
			params: {
				login: getEncryptString('', this.$password())
			}
		}).then(res => {
			if (res.data.status == 200) {
				let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
				// arr = arr.filter((el) => el.serviceStatus == '1')
				if (!tel || !name) { //
					// 首次登录 没有分配客服  直接分配
					// 随机数
					let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
					this.fenpei(arr[suiji])
				} else {
					let kefuname = arr.filter((el) => el.userName == name)
					let kefutel = arr.filter((el) => el.phone == tel)
					if (kefuname.length == 0) {
						// 若用户的客服名称不在客服列表需要重新随机分配一个在线客服
						let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
						this.fenpei(arr[suiji])
						return
					}
					if (kefuname.length > 0 && kefutel.length == 0) {
						// 若用户客服名称在客服列表但客服手机号不同需要更改用户的客服手机号
							this.kuna=kefuname[0].userName;
												this.kutel=kefuname[0].phone
						// 变更给予用户弹窗提示
						this.openpop10()
						// 用户同意后跳转到WhatsApp
	
					}else{
						if (plus.os.name == "Android") { //安卓
							if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
									pname: 'com.whatsapp', //B款app云打包的包名 
								})) { //安装了app  
								plus.runtime.openURL('whatsapp://send/?phone=' + this.kefutel,
									function(res) {
										console.log(res);
									});
							} else { //未安装app
								uni.showModal({
									title: 'WhatsApp is not installed on your phone',
									confirmText:"Confirm",
									cancelText:"Cancel",
									icon: 'none',
									duration: 2000,
								});
							}
						}
					}
	
				}
				// Math.floor(Math.random()*arr.length-1)
				// 随机数
				// let suiji = parseInt(Math.floor(Math.random() * arr.length - 1) + 1)
				// this.fenpei(arr[suiji])
			}
		})
	},
	telkefu(tel){
		if (plus.os.name == "Android") {
			//安卓
			if (
				plus.runtime.isApplicationExist({
					//查看安卓系统手机有没有下载这款app
					pname: "com.whatsapp", //B款app云打包的包名
				})
			) {
				//安装了app
				plus.runtime.openURL("whatsapp://send/?phone=" + tel, function(res) {
					// console.log(res);
				});
			} else {
				//未安装app
				uni.showModal({
					title: "WhatsApp is not installed on your phone",
					confirmText:"Confirm",
					cancelText:"Cancel",
					icon: "none",
					duration: 2000,
				});
			}
		}
	},
	// 联系客服
	kefus() {
		let tel = uni.getStorageSync("kefutel");
		let name = uni.getStorageSync("kename");
		this.kefu(tel, name);
		// 打点
		if(!uni.getStorageSync('dadian8')){
			this.nativePlug = uni.requireNativePlugin("FbKochava")
			if(this.nativePlug != null){
				this.nativePlug.eventTracking("contact_kefu","tel",uni.getStorageSync("phone"))
			}
			uni.setStorageSync('dadian8','1')
		}
		
	},
	// 保存用户信息 分配客服
	fenpei(val, val1,va) {
		let data
		// 若用户客服名称在客服列表但客服手机号不同需要更改用户的客服手机号
			if (va) {
					console.log('0001')
					console.log(this.kutel)
					data = {
						linkKefu: this.kutel, //手机号
						linkName: this.kuna, //客服名字
						accountStatus: uni.getStorageSync('brand') || '' // 机型
					}
				} else{
					if (!val1) {
						data = {
							linkKefu: val.phone, //手机号
							linkName: val.userName, //客服名字
							accountStatus: uni.getStorageSync('brand') || '' // 机型
						}
						console.log('0003')
					} else  {
						console.log('0002')
						
						// 直接分配客服
						data = {
							linkKefu: val1.phone, //手机号
							linkName: val.userName, //客服名字
							accountStatus: uni.getStorageSync('brand') || '' // 机型
						}
					}
					this.kefutel= val.phone
				}
		let datas = getEncryptString(JSON.stringify(data), this.$password())
		this.$http.post("/user/v1/save", '', {
			params: {
				login: datas
			}
		}).then(res => {
			if (res.data.status == 200) {
					this.getUserInfo("click");
				if (plus.os.name == "Android") { //安卓
					if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
							pname: 'com.whatsapp', //B款app云打包的包名 
						})) { //安装了app  
						plus.runtime.openURL('whatsapp://send/?phone=' + this.kefutel,
							function(res) {
								console.log(res);
							});
					} else { //未安装app
						uni.showModal({
							title: 'WhatsApp is not installed on your phone',
							confirmText:"Confirm",
							cancelText:"Cancel",
							icon: 'none',
							duration: 2000,
						});
					}
				}
			}
		})
	},
	// 关闭更换客服电话号 弹窗
	closepopuser() {
		this.$refs.popup10.close()
	},
	// 打开更换客服手机号 弹窗
	openpop10() {
		this.$refs.popup10.open('center')
	},
	// 同意变更手机号 则跳转 wats app
	sures() {
			this.fenpei('','',this.kutel);
		this.closepopuser();
		if (plus.os.name == "Android") { //安卓
			if (plus.runtime.isApplicationExist({ //查看安卓系统手机有没有下载这款app
					pname: 'com.whatsapp', //B款app云打包的包名 
				})) { //安装了app  
				plus.runtime.openURL('whatsapp://send/?phone=' + this.kefutel,
					function(res) {
						console.log(res);
					});
			} else { //未安装app
				uni.showModal({
					title: 'WhatsApp is not installed on your phone',
					confirmText:"Confirm",
					cancelText:"Cancel",
					icon: 'none',
					duration: 2000,
				});
			}
		}
	},
	// 用户信息获取 客服
	usermessage(){
		this.$http.get("/user/v1/getcurruser", {}).then(res => {
			if (res.data.status == 200) {
				let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
				this.kefutel=arr.linkKefu;
				this.kename=arr.linkName;
				 this.all = arr.loanAmount;
				uni.setStorageSync('kefutel',this.kefutel)
				uni.setStorageSync('kename',this.kename)
			}
		})
	},
	// 版本信息
	// banbens(){
	// 	uni.showToast({
	// 		title: this.banben,
	// 		icon: "none",
	// 		duration: 2000,
	// 	});
	// }
  },
  onBackPress(e) {
    // #ifdef APP-PLUS
    uni.exit({
      success: function () {
        console.log("应用程序成功退出");
      },
      fail: function (err) {
        console.log("退出应用程序失败:", err);
      },
    });
    // #endif
    return true;
  },

};
</script>

<style  lang="scss" scoped>
page {
  background-color: #fff;
}

.popupRef {
  display: flex;
  justify-content: center;
  align-items: center;
}

.popup {
  background: #fff;
  padding: 36rpx 42rpx;
  margin: 0 48rpx;
  border-radius: 8rpx;
  box-sizing: border-box;
}

.popup .popupTitle {
  text-align: center;
  font-weight: bold;
  color: #000;
  font-size: 36rpx;
}

.popup .popupMain {
  margin-top: 40rpx;
  padding: 0rpx 12rpx;
}

.popup .popupMain .popupText {
  font-size: 28rpx;
  color: #000;
  font-family: revert;
  font-weight: 400;
}

.popup .popupBtn {
  margin-top: 40rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.popup .popupBtn .btntext {
  height: 70rpx;
  width: 220rpx;
  border-radius: 16rpx;
  border: solid 4rpx #999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup .popupBtn .pay {
  margin-left: 60rpx;
  border: none;
  background: rgba(170, 170, 170,1);
  color: #fff;
}

.mine {
  min-height: 100vh;
  padding-bottom: 148rpx;
}

.mine .m_user {
  width: 100%;
  padding-top: 88rpx;
  padding-right: 38rpx;
  padding-left: 38rpx;
  box-sizing: border-box;
}

.mine .m_user .user_infrom {
  display: flex;
  width: 100%;
  position: relative;
  align-items: center;
  flex-direction: column;
  padding-top: 42rpx;
}

.mine .m_user .user_infrom image {
  width: 162rpx;
  height: 162rpx;
  margin-bottom: 12rpx;
}

.mine .m_user .user_infrom .u_name {
  font-size: 40rpx;
  font-family: "SourceHanSansSC-Bold", "SourceHanSansSC";
  font-weight: bold;
  color: #ffffff;
  line-height: 58rpx;
  margin-bottom: 8rpx;
}

.mine .m_user .user_infrom .u_Account {
  font-size: 30rpx;
  font-family: "SourceHanSansSC-Bold", "SourceHanSansSC";
  font-weight: 400;
  color: #ffffff;
  line-height: 42rpx;
}

.mine .m_user .user_infrom .u_Settings {
  width: 38rpx;
  height: 34rpx;
  position: absolute;
  top: 12rpx;
  right: 0;
}

.mine .m_user .user_infrom .u_Settings image {
  width: 100%;
  height: 100%;
}

.m_list {
  width: 100%;
  height: 1058rpx;
  padding-right: 26rpx;
  box-sizing: border-box;
  position: relative;
}

.m_list image {
  width: 100%;
  height: 100%;
}

.m_list .m_lists {
  width: 100%;
  position: absolute;
  top: 282rpx;
}

.m_list .m_lists .u_list {
  padding-left: 68rpx;
  padding-right: 46rpx;
  list-style: none;
  /* margin-top: 48rpx; */
}

.m_list .m_lists .u_list li {
  border-bottom: 2rpx solid transparent;
  border-color: rgba(151, 151, 151, 0.4);
  height: 120rpx;
  font-size: 26rpx;
  font-family: "SourceHanSansSC-Bold", "SourceHanSansSC";
  font-weight: 400;
  color: #1d2129;
  line-height: 44rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.m_list .m_lists .u_list li:last-child {
  border-bottom: 0;
}

.m_list .m_lists .u_list li image {
  width: 24.6rpx;
  height: 27.1rpx;
  margin-right: 32rpx;
}

.m_list .m_lists .u_list li .li_right {
  width: 14rpx;
  height: 24rpx;
}

.head-list {
  position: absolute;
  width: 46%;
  background-color: #d53030;
  border-radius: 15rpx;
  padding: 40rpx;
  box-sizing: border-box;
  position: absolute;
  top: 90rpx;
  left: 50rpx;
}

.head-text {
  color: #fff;
  font-size: 26rpx;
}

.head-text1 {
  color: #fff;
  font-size: 30rpx;
  margin-top: 16rpx;
  font-weight: bold;
}

.returns {
		width: 100% !important;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 45rpx;
	
		.pop-text {
			text-align: center;
			font-size: 24rpx;
			color: #999;
			line-height: 24rpx;
			margin-top: 10rpx;
		}
	
		.pop-btn1 {
			width: 100%;
			display: flex;
			align-items: center;
			column-gap: 50rpx;
			margin-top: 50rpx;
	
			.quit {
				width: 250rpx;
				height: 60rpx;
				line-height: 60rpx;
				color: #4787FD;
				font-size: 30rpx;
			}
	
			.closes {
				width: 250rpx;
				height: 60rpx;
				line-height: 60rpx;
				background-color: #eee;
				font-size: 30rpx;
			}
		}
	
	}
</style>
